package base.utils.date;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class DateUtils {


    public static boolean dateIsToday(String dateString , DateTypeEnum dateType){
        boolean isToday = false;

        Date date1 = TimeAndDateUtils.dateStringToDate(dateString, dateType);

        if (null == date1)  return false;

        int year =  TimeAndDateUtils.getYear(date1);
        int month = TimeAndDateUtils.getMonth(date1);
        int day = TimeAndDateUtils.getDay(date1);

        Date todayDate = getTodayDate();

        int currentYear =  TimeAndDateUtils.getYear(todayDate);
        int currentMonth = TimeAndDateUtils.getMonth(todayDate);
        int currentDay = TimeAndDateUtils.getDay(todayDate);

        if (year == currentYear && currentMonth == month && currentDay == day){
            isToday = true;
        }

        return isToday;
    }

    public static boolean dateIsYesterday(String dateString, DateTypeEnum dateType) {
        boolean isYesterday = false;

        Date date1 = TimeAndDateUtils.dateStringToDate(dateString, dateType);

        int year = TimeAndDateUtils.getYear(date1);
        int month = TimeAndDateUtils.getMonth(date1);
        int day = TimeAndDateUtils.getDay(date1);

        Date todayDate = getTodayDate();

        int currentYear = TimeAndDateUtils.getYear(todayDate);
        int currentMonth = TimeAndDateUtils.getMonth(todayDate);
        int currentDay = TimeAndDateUtils.getDay(todayDate) - 1;

        if (year == currentYear && currentMonth == month ) {
            if (1 == (currentDay - day) ) isYesterday = true;
        }

        return isYesterday;
    }


    public static String getTodayDateString(DateTypeEnum dateType){
        Date date = getTodayDate();
        SimpleDateFormat formatter = new SimpleDateFormat(dateType.getFormat());
        String dateString = formatter.format(date);
        return dateString;
    }

    public static Date getTodayDate(){
        Date date=new Date();//取时间
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(calendar.DATE, 0);//把日期往后增加一天.整数往后推,负数往前移动
        date = calendar.getTime();               //这个时间就是日期往后推一天的结果
        return date;
    }


    public  static String getWeekDateString(String dateString, DateTypeEnum dateType){
        Date date = TimeAndDateUtils.dateStringToDate(dateString, dateType);
        int weekDate = TimeAndDateUtils.getWeek(date);

        return getWeedDayString(weekDate);
    }


    public static String getWeedDayString(int dayTag){
        String weekDayString = "";
        if (1 == dayTag){
            weekDayString = "周日";
        }else if (2 == dayTag){
            weekDayString = "周一";
        }else if (3 == dayTag){
            weekDayString = "周二";
        }else if (4 == dayTag){
            weekDayString = "周三";
        }else if (5 == dayTag){
            weekDayString = "周四";
        }else if (6 == dayTag){
            weekDayString = "周五";
        }else if (7 == dayTag){
            weekDayString = "周六";
        }
        return  weekDayString;
    }







}
